﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace CalcSig
{
    public class VideoHash : ItemHash
    {
        public byte[] FileHash;
    }

    /// <summary>
    /// Very rudimentary calculator that calculates straight full file signature.
    /// </summary>
    class VideoHashCalculator : FileContentHashCalculator<VideoHash>
    {
        public static readonly string[] SupportedFileSearchMasks = { "*.mp4", "*.3gp", "*.3g2", "*.mov" };

        public VideoHashCalculator(DirectoryEnumerator fileEnumerator)
            : base(fileEnumerator.Enumerate())
        {
        }

        protected override void OnCalculateFileHash(VideoHash itemHash)
        {
            MD5 md5 = MD5.Create();

            try
            {
                using (Stream fs = new FileStream(itemHash.Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    itemHash.FileHash = md5.ComputeHash(fs);
                }
            }
            catch (Exception e)
            {
                itemHash.FileHash = null;
                Console.WriteLine(string.Format("Exception while processing {0} for file hash.  Exception: {1}", itemHash.Path, e.ToString()));
            }

            base.OnCalculateFileHash(itemHash);
        }
    }
}
